/**
 * 
 */
package com.ydy.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydy.annotation.AdminToken;
import com.ydy.annotation.CtrlParam;
import com.ydy.annotation.StaffToken;
import com.ydy.controller.base.BaseController;
import com.ydy.dto.RelationRoleAuthDTO;
import com.ydy.model.Auth;
import com.ydy.model.RelationRoleAuth;
import com.ydy.service.auth.AuthService;
import com.ydy.vo.other.BaseVo;

/**
 * @author xuzhaojie
 *
 *         2019年1月18日 上午9:17:29
 */
@Controller
@RequestMapping(value = "auth", name = "权限接口模块")
public class AuthController extends BaseController {

	@Autowired
	private AuthService authService;

	@AdminToken
	@GetMapping(value = "refresh", name = "刷新所有权限接口")
	@ResponseBody
	public ResponseEntity<BaseVo> refresh() {
		return ResponseEntity.ok(authService.refresh());
	}

	@AdminToken
	@GetMapping(value = "listAdminAuth", name = "查找管理员所有权限接口")
	@ResponseBody
	public ResponseEntity<List<Auth>> listAdminAuth() {
		return ResponseEntity.ok(authService.listAdminAuth());
	}

	@StaffToken
	@GetMapping(value = "listStaffAuth", name = "查找店员所有权限接口")
	@ResponseBody
	public ResponseEntity<List<Auth>> listStaffAuth() {
		return ResponseEntity.ok(authService.listStaffAuth());
	}

	@AdminToken
	@PostMapping(value = "save", name = "保存角色拥有权限")
	@ResponseBody
	public ResponseEntity<BaseVo> save(@RequestBody RelationRoleAuthDTO authDTO) {
		return ResponseEntity.ok(authService.save(authDTO));
	}

	@AdminToken
	@GetMapping(value = "listRoleAuths", name = "查找角色拥有权限")
	@ResponseBody
	public ResponseEntity<Map<String, RelationRoleAuth>> listRoleAuths(@CtrlParam Long roleId) {
		return ResponseEntity.ok(authService.listOneRoleAuths(roleId));
	}

}